﻿Imports AutoCAD

Public Class form_组件工具

    'Service
    Private mySqlService As IMySqlService = New MySqlServiceImpl
    Private cadApplicationService As ICadApplicationService = New CadApplicationServiceImpl
    Private cadPlateService As ICadPlateService = New CadPlateServiceImpl
    Private cadEntityDataService As ICadEntityDataService = New CadEntityDataServiceImpl
    Private entityConverterService As IEntityConverterService = New EntityConverterServiceImpl
    Private cadBlockReferenceService As ICadBlockReferenceService = New CadBlockReferenceServiceImpl


    'Mapper
    Private partSchemeHeadMapper As PartSchemeHeadMapper = New PartSchemeHeadMapper
    Private partSchemeLineMapper As PartSchemeLineMapper = New PartSchemeLineMapper

    'DataSource
    Private dt_PartSchemeHead As DataTable
    Private dt_PartSchemeLine As DataTable

    Private Sub form_组件工具_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lbl_SchemeName.Text = ""
    End Sub


    Private Sub btn_test_Click(sender As Object, e As EventArgs) Handles btn_test.Click
        Dim handle As String = "2b6" '空间图元句柄
        Dim space As AcadBlockReference = cadApplicationService.HandleToObject(handle) ' 获得空间对象

        Dim size() As Double = cadEntityDataService.GetSize(space)
        Dim position() As Double = space.InsertionPoint
        Dim rotation() As Double = New Double() {0, 0, 0}

        Dim dr_space As DataRow = dt_PartSchemeLine.NewRow
        With dr_space
            .Item("sx") = size(0)
            .Item("sy") = size(1)
            .Item("sz") = size(2)
            .Item("px") = position(0)
            .Item("py") = position(1)
            .Item("pz") = position(2)
            .Item("rx") = rotation(0)
            .Item("ry") = rotation(1)
            .Item("rz") = rotation(2)
        End With


        draw(dr_space, dt_PartSchemeLine)

    End Sub

    ''' <summary>
    ''' 设置数据源
    ''' </summary>
    Sub SetDataSource_LBPartSchemeHead()
        dt_PartSchemeHead = partSchemeHeadMapper.Select
        With lb_HoleSchemeHead
            .DataSource = dt_PartSchemeHead
            .DisplayMember = "scheme_name"
            .ValueMember = "head_id"
        End With
    End Sub

    Private Sub btn_refreshData_Click(sender As Object, e As EventArgs) Handles btn_refreshData.Click
        SetDataSource_LBPartSchemeHead()
    End Sub

    Private Sub lb_HoleSchemeHead_MouseClick(sender As Object, e As MouseEventArgs) Handles lb_HoleSchemeHead.MouseClick
        If lb_HoleSchemeHead.Items.Count < 1 Then Exit Sub
        lbl_SchemeName.Text = lb_HoleSchemeHead.SelectedItem("scheme_name")
        Dim headid As Integer = lb_HoleSchemeHead.SelectedItem("head_id")
        dt_PartSchemeLine = partSchemeLineMapper.Select_ByHeadId(headid)
        dgv_HoleSchemeLine.DataSource = dt_PartSchemeLine
        dgv_HoleSchemeLine.AutoResizeColumns()
    End Sub

    Private Sub btn_draw_Click(sender As Object, e As EventArgs) Handles btn_draw.Click
        Dim handle As String = ""
        Dim br As AcadBlockReference = cadApplicationService.HandleToObject(handle)

    End Sub


    Private Sub draw(ByRef dr_space As DataRow, ByRef dt_plates As DataTable)

        Dim entity As PlateEntity
        For Each dr_plate As DataRow In dt_plates.Rows
            entity = entityConverterService.ConverterPlateEntity(dr_space, dr_plate)
            cadPlateService.DrawPlate(entity)
        Next dr_plate


    End Sub
End Class